using KL.Core.Common.MyOptions;
using KL.Standard.Mongo.Repositories;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;

namespace KL.Core.Extensions.MongoDB;

public static  class MongoDBSetup
{
    /// <summary>
    /// 添加mongodb的设置
    /// </summary>
    /// <param name="services"></param>
    /// <param name="Configuration"></param>
    /// <exception cref="ArgumentNullException"></exception>
    public static void AddMongoDbSetup(this IServiceCollection services, ConfigurationManager Configuration)
    {
        if (services == null) throw new ArgumentNullException(nameof(services));
        var mongoDbOptions = Configuration.GetSection("MongoDB").Get<MongoDBOptions>();
        if (mongoDbOptions?.Enabled ?? false)
        {
            services.AddSingleton<KLMongoClient>();
        }
    }
}